//
// Created by chizuru on 2025/9/25.
//

#pragma once
#include "libserialport.h"
#include <string>
std::string printLibSerialPortErrorMessage(enum sp_return result)
{
    std::string error;
    char* error_message;
    switch (result) {
        case SP_ERR_ARG:
            error = "Error: Invalid argument.\n";
            break;
        case SP_ERR_FAIL:
            error_message = sp_last_error_message();
            error = error_message;
            sp_free_error_message(error_message);
            break;
        case SP_ERR_SUPP:
            error = "Error: Not supported.\n";
            break;
        case SP_ERR_MEM:
            error = "Error: Couldn't allocate memory.\n";
            break;
        case SP_OK:
        default:
            error = "OK.\n";
    }
    return error;
}